import Vue from 'vue'
import Vuex from 'vuex'
import { INCREMENT, DECREMENT } from './mutations-types'

// 1.下载
Vue.use(Vuex)

const store = new Vuex.Store({
  // 保存状态
  state: {
    count: 1000,
    students: [
      { age: 18, name: 'huyong' },
      { age: 20, name: 'lwt' },
      { age: 16, name: 'kobe' }
    ]
  },
  mutations: {
    [INCREMENT](state) {
      state.count++
    },
    [DECREMENT](state) {
      state.count--
    }
  },
  actions: {

  },
  getters: {
    powerCount(state) {
      return state.count * state.count
    },
    more18Students(state) {
      return state.students.filter(s => s.age > 18)
    },
    more18StudentsLength(state, getters) {
      return getters.more18Students.length
    },
    moreXStudents(state) {
      return age => state.students.filter(s => s.age > age)
    }
  },
  modules: {

  }
})

export default store